const data = [23, 23, 22, 22, 22]
let sum = 0
const seriesData = []
data.forEach(function (item) {
  sum += item
})
let avgValue = sum / 100 // 间隙数据
data.forEach(function (item, index) {
  // 实际展示数据
  const listName = ['粮食作物', '养殖', '数字乡村', '设施农业', '经济作物']
  seriesData.push({
    name: listName[index],
    value: item,
    unit: ''
  })
})
const colorList = ['#26ffcb', '#2651ff', '#35fbf4', '#5126ff', '#24cbff']
const colorListBottom = ['#20c6ca', '#204dee', '#2bc4e7', '#3e2eee', '#1fa2ee']
const option = {
  grid: {
    width: '100%',
    height: '100%',
    left: 0,
    top: 0,
    show: true,
    borderColor: 'transparent',
    backgroundColor: 'transparent',
  },
  tooltip: {
    trigger: 'item',
    formatter: function(params) {
      return params.name + ':' + params.value + '%'
    }
  },
  legend: [
    {
      show: false
    }
  ],
  title: [
    {
      show: false
    }
  ],
  series: [
    {
      type: 'pie',
      z: 3,
      center: ['50%', '50%'],
      radius: ['30%', '45%'],
      clockwise: true,
      avoidLabelOverlap: true,
      emphasis: {
        scale: true,
        scaleSize: 10
      },
      itemStyle: {
        normal: {
          color: (params) => {
            return colorList[params.dataIndex]
          },
          borderColor: '#142547',
          borderWidth: 0
        }
      },
      labelLine: {
        show: true,
        normal: {
          lineStyle: {
            color: '#1fa2ee'
          }
        }
      },
      label: {
        formatter: '{c|{c}%} \n{hr|}\n {b|{b}} ',
        rich: {
          hr: {
            borderColor: '#1fa2ee',
            width: '100%',
            borderWidth: 0.5,
            height: 0
          },
          b: {
            fontSize: 12,
            lineHeight: 25,
            align: 'center',
            padding: [2, 2],
            color: '#fff'
          },
          c: {
            fontSize: 12,
            lineHeight: 25,
            align: 'center',
            color: '#66FFFF'
          }
        }
      },
      data: seriesData
    },
    {
      type: 'pie',
      z: 3,
      center: ['50%', '50%'],
      radius: ['23%', '31%'],
      clockwise: true,
      avoidLabelOverlap: true,
      emphasis: {
        scale: true,
        scaleSize: 0
      },
      itemStyle: {
        normal: {
          color: (params) => {
            return colorListBottom[params.dataIndex];
          },
          borderColor: '#142547',
          borderWidth: 0
        }
      },
      labelLine: {
        show: true
      },
      label: {
        normal: {
          formatter: (params) => {
            // console.log(params)
            return '{name|' + params.name + '}\n{value|' + params.value + '}'
          },
          //   padding: [0, -100, 25, -100],
          rich: {
            name: {
              fontSize: 12,
              color: '#fff'
            },
            value: {
              fontSize: 12,
              padding: [5, 0, 0, 0],
              color: '#FFC02E'
            }
          }
        }
      },
      data: seriesData
    }
  ]
}
// 自动轮播

export default option
